package main

import (
	"net/http"
	"net/http/httputil"
	"fmt"
)

func main() {
	var url = "http://www.imooc.com"
	request, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		panic(err)
	}
	request.Header.Add("User-Agent","Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Mobile Safari/537.36")
	//resp, err := http.Get("http://www.imooc.com")
	cilent := http.Client{
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			fmt.Println("Redirect:",req)
			return nil
		},
	}
	resp, err := cilent.Do(request)
	if err != nil {
		panic(err)
	}
	s, err := httputil.DumpResponse(resp,true)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%s",s)
}
